package cn.com.infohold.smartcity.activity;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import java.io.Serializable;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.api.bean.Message;
import cn.com.infohold.smartcity.parent.ParentActivity;
import cn.com.infohold.smartcity.utils.PushUtils;
import cn.com.infohold.smartcity.utils.StringUtils;
import common.annotation.ViewInject;

/**
 * Created by Mr.Fan on 2017/4/30.
 */

public class MessageDetailActivity extends ParentActivity {

    @ViewInject(R.id.toolbar)
    private Toolbar mToolbar;
    @ViewInject(R.id.toolbar_title)
    private TextView mTitleView;

    @ViewInject(R.id.activity_message_detail_title)
    private TextView mTitle;
    @ViewInject(R.id.activity_message_detail_sender_label)
    private TextView mSenderLabel;
    @ViewInject(R.id.activity_message_detail_sender)
    private TextView mSender;
    @ViewInject(R.id.activity_message_detail_date_label)
    private TextView mDateLabel;
    @ViewInject(R.id.activity_message_detail_date)
    private TextView mDate;

    @ViewInject(R.id.frgm_main_inform_content)
    private TextView mContent;

    @Override
    protected Object inflateView() {
        return R.layout.activity_message_detail;
    }

    @Override
    protected void initView(View anchor) {
        setSystemBar();
        initToolBar();

        Intent intent = getIntent();
        Message message = (Message) intent.getSerializableExtra(Serializable.class.getName());
        if (message == null) {
            return;
        }
        PushUtils.getInstance(getApplicationContext()).pop(message.getId());


        mTitle.setText(message.getTitle());
        mSenderLabel.setText(StringUtils.fixedKey(mSenderLabel.getText().toString()));
        mSender.setText(message.getSender());
        mDateLabel.setText(StringUtils.fixedKey(mDateLabel.getText().toString()));
        mDate.setText(message.getSendDate());
        mContent.setText(message.getContent());
    }


    private void initToolBar() {
        mTitleView.setText(getString(R.string.my_message_detail));
        setSupportActionBar(mToolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    @Override
    public void finish() {
        super.finish();
        overridePendingTransitionFade();
    }
}
